package com.hz.ruoyilgorder.config;

import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

import java.time.Duration;

/**
 * @Author: wzy
 * @Date: 2024/12/23 16:26
 * @Description:  通过#号分隔符，对内容就行分割
 */
public class MyRedisCacheManager extends RedisCacheManager {

    public MyRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {
        super(cacheWriter, defaultCacheConfiguration);
    }

    public RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfig) {
        String arrays[] = StringUtils.delimitedListToStringArray(name,"#");  //proCache#1000
        if(arrays.length>1){
            name = arrays[0];
            cacheConfig = cacheConfig.entryTtl(Duration.ofSeconds(Long.parseLong(arrays[1])));
        }

        return super.createRedisCache(name,cacheConfig);
    }





}
